package com.example.zhuyu.basemvp.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

/**
 * @author zhuyu
 * @desc 工具类
 */
public class Util {
    /**
     * 检查空指针异常
     *
     * @param errorMsg 异常log
     */
    public static void checkNullException(Object obj, String errorMsg) {
        if (obj == null) {
            throw new NullPointerException(errorMsg);
        }
    }

    /**
     * 检查空指针异常
     */
    public static void checkNullException(Object object) {
        if (object == null) {
            throw new NullPointerException("Please check value");
        }
    }

    public static String getAppName(Context context) {
        PackageManager pm = context.getPackageManager();
        try {
            PackageInfo info = pm.getPackageInfo(context.getPackageName(), 0);
            int labelRes = info.applicationInfo.labelRes;
            return context.getResources().getString(labelRes);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return "";
    }
}